from typing import List


class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        i, j = 0, 0
        while j < len(nums):
            if nums[j] == val:
                while j < len(nums) and nums[j] == val:
                    j += 1
            if j >= len(nums):
                break
            nums[i] = nums[j]
            i += 1
            j += 1
        return i


if __name__ == "__main__":
    nums = [2, 3, 3, 0, 0, 1, 1, 1]
    val = 1
    print(Solution().removeElement(nums, val))
    print(nums)
    pass
